package com.hapzxb.consumer;

import com.hapzxb.consumer.irule.ConstomRule;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;

import java.util.ArrayList;
import java.util.List;

/**
 * 指定service接口所在的包，开启OpenFeign客户端
 */
@EnableFeignClients(basePackages = "com.hapzxb.consumer.service")
@SpringBootApplication
@EnableEurekaClient
public class ConsumerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConsumerApplication.class, args);
    }

    /**
     *  设置负载均衡算法为“随机算法”
     * @return
     */
    @Bean
    public IRule loadBalanceRule(){
        // 指定要排除的Server的端口号
        List<Integer> ports = new ArrayList<>();
        ports.add(8082);
        return new ConstomRule(ports);

//        return new RandomRule();
    }

}
